<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <title th:text="${question.title}"></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/css/bootstrap-theme.min.css">
    <link rel="stylesheet" type="text/css" href="/css/community.css">
    <link rel="stylesheet" type="text/css" href="/css/editormd.preview.min.css">


    <script type="application/javascript" src="/js/jquery.min.js"></script>
    <script type="application/javascript" src="/js/bootstrap.min.js"></script>
    <script type="application/javascript" src="/js/wangEditor.min.js"></script>
    <script type="application/javascript" src="/js/comment.js"></script>
    <!--    <script src="https://unpkg.com/dayjs"></script>-->
    <script type="application/javascript" src="/js/dayjs.js"></script>
    <script type="application/javascript" src="/js/question.js"></script>
    <script type="application/javascript" src="/js/editormd.min.js"></script>
    <script type="application/javascript" src="/js/lib/marked.min.js"></script>
    <script type="application/javascript" src="/js/lib/prettify.min.js"></script>

</head>
<body>
<div th:insert="navigation :: nav"></div>
<div class="container-fluid main profile">
    <div class="row">
        <!--左边栏-->
        <div class="col-lg-9 col-md-12 col-sm-12 col-xs-12">
            <!--问题详情-->
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <h3><span th:text="${question.title}"></span></h3>
                <span class="text-desc">
                <span th:text="${question.viewCount}"></span>
                    | 作者：<span th:text="${question.user.name}"></span>
                    | 发布时间：<span th:text="${#dates.format(question.gmtCreate, 'yyyy-MM-dd HH:mm')}"></span>
                    | 浏览次数：<span th:text="${question.viewCount}"></span>
                </span>
                <hr class="hr-sp-up hr-sp-down">
                <div id="description" class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <textarea style="display: none; width: 100%" th:text="${question.description}"></textarea>
                </div>
                <script type="application/javascript">
                    $(function () {
                        editormd.markdownToHTML('description', {});
                    });
                </script>
            </div>
            <!--标签-->
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <hr class="hr-sp-up hr-sp-down">
                <span class="label label-info span-sp-right" th:each="tag : ${question.tag.split(',')}">
                    <span class="glyphicon glyphicon-tags"></span>
                    <span th:text="${tag}"></span>
                </span>
            </div>
            <!--编辑-->
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <hr class="hr-sp-up hr-sp-down">
                <a th:href="@{'/publish/'+${question.id}}" class="community-menu"
                   th:if="${question.user.accountId == #request.session.getAttribute('userAccountId')}">
                    <span class="glyphicon glyphicon-pencil" aria-hidden="true">
                    </span>编辑
                </a>
            </div>
            <!--已收到的评论-->
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 div-sp-up">
                <h4><span th:text="${question.commentCount}"></span> 个回复</h4>
                <hr class="comment-sp hr-sp-down">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" th:each="comment : ${comments}">
                    <div class="media">
                        <div class="media-left">
                            <a href="#">
                                <img class="media-object img-rounded img-size-head" th:src="${comment.user.avatarUrl}">
                            </a>
                        </div>
                        <div class="media-body" th:id="${'comment-body-'+comment.id}">
                            <div th:text="${comment.user.name}"></div>
                            <div th:text="${comment.content}"></div>
                            <div class="comment-menu">
                                <form>
                                    <span class="glyphicon glyphicon-thumbs-up glyphicon-style"
                                          id="like-icon" name="like-icon"
                                          tabindex="0"
                                          onclick="changeLikeCommentState(this)"
                                          onblur="setLikeState()"
                                          th:data-id="${comment.id}"></span>
                                    <span class="glyphicon glyphicon-comment glyphicon-style"
                                          id="second-comment-icon"
                                          th:data-id="${comment.id}"
                                          th:text="${comment.commentedCount}"
                                          onclick="collapseComments(this)"></span>
                                    <span class="comment-time"
                                          th:text="${#dates.format(comment.gmtCreate, 'yyyy-MM-dd')}"></span>
                                </form>
                            </div>
                            <!--二级评论-->
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 collapse sub-comments"
                                 th:id="${'comment-' + comment.id}">
                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                    <input type="text" class="form-control" placeholder="评论一下..."
                                           th:id="${'input-' + comment.id}">
                                    <button type="button" class="btn btn-default btn-comment"
                                            onclick="collapseSecondComments()">取消
                                    </button>
                                    <button type="button" class="btn btn-success btn-comment" th:data-id="${comment.id}"
                                            onclick="comment(this)">评论
                                    </button>
                                </div>
                            </div>
                        </div>
                        <hr class="comment-menu">
                    </div>
                </div>
            </div>
            <!--回复输入文本框-->
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 div-sp-up">
                <h4>提交回复</h4>
                <hr class="comment-sp">
                <div class="media">
                    <div class="media-left">
                        <a href="#">
                            <img class="media-object img-rounded img-size-head"
                                 th:src="${session.user != null ? session.user.avatarUrl : '/img/default-avatar.png'}">
                        </a>
                    </div>
                    <div class="media-body">
                        <span th:text="${session.user != null ? session.user.name : '要回复文章请先登录或注册！'}"></span>
                    </div>
                    <div class="media-right">
                        <a href="#">
                            <h5 class="media-heading">积分规则</h5>
                        </a>
                    </div>
                </div>
            </div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div id="editor"></div>
                <textarea id="comment" style="width:100%; height:200px; display: none" class="form-control"
                          name="comment"
                          cols="30" rows="10"></textarea>
                <!-- 注意， 只需要引用 JS，无需引用任何 CSS ！！！-->
                <script type="text/javascript">
                    var E = window.wangEditor;
                    var editor = new E('#editor');
                    var $text1 = $('#comment');
                    console.info($text1.val());
                    // 或者 var editor = new E( document.getElementById('editor') )
                    editor.customConfig.onchange = function (html) {
                        // 监控变化，同步更新到 textarea
                        $text1.val(html)
                    };
                    editor.create();
                    editor.txt.clear();
                    // $text1.val(editor.txt.html());
                    editor.txt.append($text1.val());
                </script>
            </div>
            <input type="hidden" th:value="${question.id}" id="questionId">
            <!--提交回复-->
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <button class="btn btn-success btn-publish" onclick="postComment()">回复</button>
            </div>
        </div>
        <!--右边栏-->
        <div class="col-lg-3 col-md-12 col-sm-12 col-xs-12">
            <!--问题发起人-->
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 div-sp-up">
                <h4>发起人</h4>
                <hr class="hr-sp-up hr-sp-down">
                <div class="media">
                    <div class="media-left">
                        <a href="#">
                            <img class="media-object img-rounded img-size" th:src="${question.user.avatarUrl}">
                        </a>
                    </div>
                    <div class="media-body">
                        <h5 class="media-heading">
                            <span th:text="${question.user.name}"></span>
                        </h5>
                        <span>大爱 Saber~~</span>
                    </div>
                </div>
            </div>
            <!--相关问题-->
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 div-sp-up div-sp-down">
                <h4>相关问题</h4>
                <hr class="hr-sp-up hr-sp-down">
                <div class="list-group">
                    <ul class="question-related">
                        <li class="list-group-item" th:each="relatedQuestion : ${relatedQuestions}">
                            <a th:href="@{'/question/' + ${relatedQuestion.id}}" th:text="${relatedQuestion.title}"></a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>